package ThreadDemo;

public class ThreadDemo02 {
    private static long count=100_0000_0000L;
    public static void main(String[] args) {
//        serial();
        concurrency();
    }
    public static void serial(){
        long beg=System.nanoTime();
        long beg2=System.currentTimeMillis();
        long a=0;
        for(long i=0;i<count;i++){
            a++;
        }
        int b=0;
        for(long i=0;i<count;i++){
            b++;
        }
        long end=System.nanoTime();
        long end2= System.currentTimeMillis();
        System.out.println(end-beg);
//        System.out.println(end2-beg2);
    }
    public static void concurrency(){
        long beg=System.nanoTime();
        long beg2=System.currentTimeMillis();
        Thread t1=new Thread(()->{
           int a=0;
           for(int i=0;i<count;i++){
               a++;
           }
        });
        Thread t2=new Thread(()->{
            int a=0;
            for(int i=0;i<count;i++){
                a++;
            }
        });

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end=System.nanoTime();
        long end2= System.currentTimeMillis();
        System.out.println(end-beg);
//        System.out.println(end2-beg2);
    }
}
